Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add GetTimestampAtHeight to client state #888

Closed
wants to merge 7 commits into from

Conversation

notbdu
Copy link
Contributor

@notbdu notbdu commented Feb 9, 2022

Description

Add the GetTimetstampAtHeight to each client state + unit tests

  • 06-solomachine
  • 07-tendermint
  • 09-localhost

PR 1/2 for: #876


Before we can merge this PR, please make sure that all the following items have been
checked off. If any of the checklist items are not applicable, please leave them but
write a little note why.

  • Targeted PR against correct branch (see CONTRIBUTING.md)
  • Linked to Github issue with discussion and accepted design OR link to spec that describes this work.
  • Code follows the module structure standards.
  • Wrote unit and integration tests
  • Updated relevant documentation (docs/) or specification (x/<module>/spec/)
  • Added relevant godoc comments.
  • Added a relevant changelog entry to the Unreleased section in CHANGELOG.md
  • Re-reviewed Files changed in the Github PR explorer
  • Review Codecov Report in the comment section below once CI passes

Copy link
Contributor

@crodriguezvega crodriguezvega left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this PR, @notbdu!

@@ -39,6 +39,20 @@ func (cs ClientState) GetLatestHeight() exported.Height {
return clienttypes.NewHeight(0, cs.Sequence)
}

// GetTimestampAtHeight returns 0.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this comment correct? The implementation seems to indicate that a non-zero timestamp could also be returned...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, forgot to update the comment here... 🤦‍♂️

) (uint64, error) {
consensusState, err := GetConsensusState(clientStore, cdc, height)
if err != nil {
return 0, err
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason not to return the error wrapped like you do for the tendermint client (i.e. sdkerrors.Wrapf(err, "height (%s)", height,))?

@colin-axner
Copy link
Contributor

Thanks for the pr's @notbdu. I might have forgotten to mention that we plan to merge all the 02-client changes into a separate feature branch. It still needs to be created, but I can make it now. Would you mind changing the target branch to it?

Copy link
Contributor

@colin-axner colin-axner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice start! Main requested changes is in relation to the solo machine

@notbdu notbdu changed the base branch from main to 02-client-refactor February 11, 2022 00:25
@codecov-commenter
Copy link

Codecov Report

Merging #888 (15544bf) into 02-client-refactor (d5e2ba5) will increase coverage by 0.01%.
The diff coverage is 87.50%.

Impacted file tree graph

@@                  Coverage Diff                   @@
##           02-client-refactor     #888      +/-   ##
======================================================
+ Coverage               79.85%   79.86%   +0.01%     
======================================================
  Files                     150      150              
  Lines                   10803    10819      +16     
======================================================
+ Hits                     8627     8641      +14     
- Misses                   1752     1754       +2     
  Partials                  424      424              
Impacted Files Coverage Δ
modules/core/02-client/legacy/v100/solomachine.go 6.34% <0.00%> (-0.21%) ⬇️
...light-clients/06-solomachine/types/client_state.go 63.53% <100.00%> (+0.69%) ⬆️
.../light-clients/07-tendermint/types/client_state.go 72.78% <100.00%> (+0.61%) ⬆️
...s/light-clients/09-localhost/types/client_state.go 93.28% <100.00%> (+0.09%) ⬆️

@notbdu
Copy link
Contributor Author

notbdu commented Mar 9, 2022

This is ready for another pass btw!

Copy link
Contributor

@seantking seantking left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM but would like a review from @colin-axner.

Thanks for the great work 🤝

Copy link
Contributor

@colin-axner colin-axner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fantastic work! Really appreciated the clean tests. There's small fix regarding solo machines.

Could you add a changelog entry as well? Thanks again!

Comment on lines 49 to 51
if !cs.GetLatestHeight().EQ(height) {
return 0, sdkerrors.Wrapf(ErrInvalidSequence, "not latest height (%s)", height)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this can be removed. The solo machine only has a single consensus state (the latest consensus state). This function is used when checking if a packet has timed out, so we want to compare the packet timestamp against the latest consensus state, as this would be the consensus state used process the timeout proof

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually on further consideration, we should return an error if the height passed in is not associated with an expected proof height of cs.GetLatestHeight().Increment()

@notbdu
Copy link
Contributor Author

notbdu commented Mar 25, 2022

Thanks for the review! I just rebased and pushed.

cdc codec.BinaryCodec,
height exported.Height,
) (uint64, error) {
if !cs.GetLatestHeight().Increment().EQ(height) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if !cs.GetLatestHeight().Increment().EQ(height) {
if !cs.GetLatestHeight().EQ(height) {

Sorry I was incorrect!

The solo machine stores the current sequence of the next proof it'll verify. In the timeout case it'll either be verifying absence of next seq recv (ordered channels) or packet receipt absence (unordered channels). I'm not sure why I got mixed up, but the sequence is incremented after verifying and this function is always called before verifying. So the height passed in should match the current sequence. The only time it won't is during connection handshake verification which doesn't need to rely on GetTimestampAtHeight

@colin-axner
Copy link
Contributor

closed by #1659

oshorefueled pushed a commit to ComposableFi/ibc-go that referenced this pull request Aug 9, 2022
CosmosCar pushed a commit to caelus-labs/ibc-go that referenced this pull request Nov 6, 2023
Closes: cosmos#887

Copy parts of [share
package](https://github.com/celestiaorg/celestia-app/tree/main/pkg/shares)
relating to compact shares. We plan to later extract common code into a
separate repo that both `celestia-app` and `rollkit` can use.

Changes needed to this code for use in rollkit will be handled in a
later PR.

Also, extracts parts needed to resolve dependencies, specifically,
`namespace`, `appconsts`, and `testfactory.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants